package com.bank.view;

import com.bank.javabean.Account;
import com.bank.service.AdminService;
import com.bank.service.UserService;
import com.bank.serviceimpl.AdminServiceImpl;
import com.bank.serviceimpl.UserServiceImpl;

import java.util.Scanner;

/**
 * @Auther: Liu
 * 试图与service建立连接
 */
//主页面
public class MainView {
    public static void main(String[] args) {
        AdminService adminService=new AdminServiceImpl();
        UserService userService=new UserServiceImpl();
        Scanner scInt=new Scanner(System.in);
        Scanner scString=new Scanner(System.in);
        System.out.println("======欢迎光临天地银行管理系统======");
        while(true){
            System.out.println("请输入你的选择1-登录 2-忘记密码 3-退出");
            int choose = scInt.nextInt();
            if(choose==1){
                System.out.println("请输入账号类型");
                int type = scInt.nextInt();
                System.out.println("请输入账号");
                String username = scString.nextLine();
                System.out.println("请输入密码");
                String password = scString.nextLine();
                if(type==1){
                    //调用管理员登录服务
                    Account account = adminService.AdminLogin(username, password);
                    if(account!=null){//返回值不为null
                        //登录成功调整到管理员页面
                        AdminView.view(account);
                    }
                }else if(type==2){
                    //调用用户登录服务服务
                    Account account = userService.UserLogin(username, password);
                    if(true){//返回值不为null
                        UserView.view(account);
                    }
                }
            }else if(choose==2){
                System.out.println("请输入账号");
                String username = scString.nextLine();
                System.out.println("请输入账号类型");
                int type = scInt.nextInt();
                adminService.forgetPassword(username,type);
                System.out.println("您的账号密码已被修改为初始密码");
            }else{
                break;
            }
        }
    }
}

